<?php
/*******************************************************************************

    FinalsClub.org is a platform for students and faculty to collaborate
    and share their knowledge with the world.

    Copyright (C) 2009  Andrew Magliozzi
 
    This file is a part of FinalsClub.org.

    FinalsClub.org is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
    To contact FinalsClub.org, send an email to info@finalsclub.org, or
    send mail to Finals Club, c/o Veritas Tutors, 1132 Massachusetts Avenue,
    Cambridge, MA 02138.

*******************************************************************************/

/**
 * Course form.
 *
 * @package    FinalsClub
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormTemplate.php 10377 2008-07-21 07:10:32Z dwhittle $
 */
class CourseForm extends BaseCourseForm {

	public function configure() {
		$this->widgetSchema['user_id'] = new sfWidgetFormInputHidden();
		$this->widgetSchema['network_id'] = new sfWidgetFormInputHidden();
		$this->widgetSchema['status'] = new sfWidgetFormInputHidden();
		$this->widgetSchema['course_id'] = new sfWidgetFormInputHidden();
		
		$semesters = SemesterPeer::retrieveAll();
		$semesterOptions = array();
		foreach($semesters as $semester) {
			$semesterOptions[$semester->getId()] = $semester->getTerm() . ' ' . $semester->getYear('Y');
		}
		$this->widgetSchema['semester_id'] = new sfWidgetFormSelect(array(
			'choices' => $semesterOptions));
		
		$currentSemester = SemesterPeer::retrieveCurrent();
		$this->setDefault('semester_id', $currentSemester->getId());
		
		$this->validatorSchema['user_id'] = new sfValidatorPass();
		$this->validatorSchema['semester_id'] = new sfValidatorPass();
		$this->validatorSchema['network_id'] = new sfValidatorPass();
		
		$this->validatorSchema['instructor_name'] = new sfValidatorString(array('required' => true),
			array('required' => 'Please enter the name of the instructor')
		);
		$this->validatorSchema['instructor_email'] = new sfValidatorString(array('required' => true),
			array('required' => 'Please enter the email address of the instructor')
		);
		$this->validatorSchema['name'] = new sfValidatorString(array('required' => true),
			array('required' => 'Please enter the name of the course')
		);
		$this->validatorSchema['description'] = new sfValidatorString(array('required' => true),
			array('required' => 'Please enter a description for this course')
		);

		// retrieve possible subjects for creation
		$c = new Criteria();
		$c->addDescendingOrderByColumn(SubjectPeer::NAME);
		$subjects = SubjectPeer::doSelect($c);
		$subjectOptions = array();
		$subjectValues = array();
		foreach($subjects as $subject) {
			$subjectOptions[$subject->getId()] = $subject->getName();
			$subjectValues[] = $subject->getId();
		}
		$this->widgetSchema['subject_id'] = new sfWidgetFormSelect(array(
			'choices' => $subjectOptions));
		
		/*$this->validatorSchema['subject_id'] = new sfValidatorChoice(
			array('choices' => $subjectValues, 'multiple' => false),
			array('required' => 'You must select at least one subject for this course.',
				'invalid' => 'You have selected an invalid subject for this course.')
		);*/

	    $this->validatorSchema->setOption('allow_extra_fields', true);
		$this->validatorSchema->setOption('filter_extra_fields', false);		
	}
}
